package com.xuhuan.demo.principle.ocp;

/**
 * @author huan.xu
 * @date 2021/10/1 22:21
 * @description 开闭原则
 */
public class Ocp1 {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new A());
        graphicEditor.drawShape(new B());
    }
}

/**
 * 绘制图形工具类
 */
class GraphicEditor{
    public void drawShape(Shape shape){
        shape.draw();
    }
}

/**
 * 图形
 */
abstract class Shape{
    public abstract void  draw();
}

/**
 * 图形A
 */
class A extends Shape{
    @Override
    public void draw() {
        System.out.println("绘制图形A");
    }
}

/**
 * 图形B
 */
class B extends Shape{
    @Override
    public void draw() {
        System.out.println("绘制图形B");
    }
}